package cn.hs.controller;

import cn.hs.entity.Demo;
import cn.hs.service.DemoService;
import cn.hs.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName DemoController
 * @Description TODO
 * @Author CnYuu
 * @Date 2024年10月21日 14:37
 * @Version 1.0
 */
@RestController
@RequestMapping("/demo")
public class DemoController {
    @Autowired
    private DemoService demoService;
    @GetMapping("/selectAll")
    public Result selectAll(Demo demo){
        List<Demo> demos = demoService.selectAll(demo);
        demos.forEach(e-> System.out.println(e));
        return Result.success(demos);
    }
    @PostMapping("/selectById")
    public Result selectById(int id){
        List<Demo> demos = demoService.selectById(id);
        demos.forEach(e-> System.out.println(e));
        return Result.success(demos);
    }
    @PostMapping("/insert")
    public Result insert(Demo demo){
        int num = demoService.insert(demo);
        return Result.success("添加成功");
    }
    @PostMapping("/update")
    public Result update(Demo demo){
        int num = demoService.update(demo);
        return Result.success("修改成功");
    }
    @PostMapping("/delete")
    public Result delete(int id){
        int num = demoService.delete(id);
        return Result.success("删除成功");
    }
}
